package com.gopay.common.security.validcode.service.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gopay.common.constants.validcode.CodeType;
import com.gopay.common.domain.vs.VsValidCodeDtl;
import com.gopay.common.security.validcode.manager.ValidCodeManager;
import com.gopay.common.security.validcode.service.ValidCodeService;

/**
 * 验证码接口实现
 * 
 * @ValidCodeServiceImpl.java
 * @author yaobo
 * @2013-5-15 下午04:03:13 www.gopay.com.cn Inc.All rights reserved.
 */
@Service("validCodeService")
public class ValidCodeServiceImpl implements ValidCodeService {
    @Resource(name = "tradeValidCodeManager")
    private ValidCodeManager tradeValidCodeManager;

    @Resource(name = "userValidCodeManager")
    private ValidCodeManager userValidCodeManager;

    @Resource(name = "personBindValidCodeManager")
    private ValidCodeManager personBindValidCodeManager;
    
    @Resource(name = "payValidCodeManager")
    private ValidCodeManager payValidCodeManager;

    @Override
    public VsValidCodeDtl generate(CodeType type, String voID) {
        if (type == CodeType.USER) {
            return userValidCodeManager.generate(type, voID);
        } else if (type == CodeType.TRADE) {
            return tradeValidCodeManager.generate(type, voID);
        } else if (type == CodeType.PERSON_BIND) {
            return personBindValidCodeManager.generate(type, voID);
        } else if(type == CodeType.PAY){
        	return payValidCodeManager.generate(type, voID);
        } else {
            return null;
        }
    }

    @Override
    public boolean valid(CodeType type, String voID, String code) {
        if (type == CodeType.USER) {
            return userValidCodeManager.valid(type, voID, code);
        } else if (type == CodeType.TRADE) {
            return tradeValidCodeManager.valid(type, voID, code);
        } else if (type == CodeType.PERSON_BIND) {
            return personBindValidCodeManager.valid(type, voID, code);
        }

        return false;
    }


	@Override
	public boolean valid(CodeType type, String voID, String code, String timeOut) {
		if(type== CodeType.PAY){
			return payValidCodeManager.valid(type, voID, code,timeOut);
		}
		return false;
	}

}
